package com.xinyan.controller;

import com.xinyan.service.ValidateCodeService;
import com.xinyan.vo.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class TestController {

    @Autowired
    private ValidateCodeService validateCodeService;

    @GetMapping("test")
    public String test(){
        return "hello";
    }

    @GetMapping("/validataCode")
    public void validataCode(HttpServletResponse response) throws IOException {
        response.setHeader("Cache-Control", "no-store, no-cache");
        response.setContentType("image/jpeg");
        ServletOutputStream outputStream = response.getOutputStream();
        ValidateCode validateCode = validateCodeService.createValidateCode();
        ImageIO.write(validateCode.creatCode(),"png",outputStream);
        outputStream.flush();
        outputStream.close();
    }
}
